<template>
  <div>
    <!-- 缓存组件 -->
    <transition name="slide-fade" mode="out-in">
      <keep-alive :include="keepAlives">
        <router-view></router-view>
      </keep-alive>
    </transition>
  </div>
</template>

<script>
export default {
  data() {
    return {
      keepAlives: []
    }
  },
  watch: {
    $route: function (route) {
      // console.log(route);
      if (route.meta.keepAlive && this.keepAlives.indexOf(route.name) == -1) {
        this.keepAlives.push(route.name)
      }
    }
  }
}
</script>

<style type='text/css'>
.slde-fade-enter-active {
  transition: all 0.8s ease-out;
}
.slide-fade-leave-active {
  transition: all 0.8s cubic-bezier(1, 0.5, 0.8, 1);
}
.slide-fade-enter-from,
.slide-fade-leave-to {
  transform: translateX(-500px);
  opacity: 0;
}
</style>